'''
Created on Apr 6, 2011

@author: mwarren1
'''
import wx
import webbrowser
from wx.tools.dbg import Logger

import resources

from maildroplibs import ENABLEDEBUG, DEBUGSTREAM, VERSION

import TutorialGUI

debug = Logger('AboutGUI')
debug.SetStream(DEBUGSTREAM)
debug(enable = ENABLEDEBUG)

class AboutGUI(wx.Frame):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''

        winSize = (465,225)
        if 'wxGTK' in wx.PlatformInfo:
            winSize = (465,195)
        
        wx.Frame.__init__(self, None, title = "About MailDrop", size=winSize, style=wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN)
        
#        if 'wxMac' in wx.PlatformInfo:
#            self.mgr = wx.aui.AuiManager()
#            self.mgr.SetManagedWindow(self)
        
        icon = resources.MakeIcon(resources.getBoxIconImage())
        self.SetIcon(icon)
        
        self.boxBitmap = resources.getBoxIconBitmap()
        self.donateBitmap = resources.getDonateButtonBitmap()
        
        self.donateClickBox = wx.Rect(360, 100, self.donateBitmap.GetWidth(), self.donateBitmap.GetHeight())
        self.tutorialClickBox = wx.Rect(380, 140, 69, 15)
        self.siteClickBox = wx.Rect(340, 172, 110, 15)
        
        #wx.EVT_PAINT(self, self.OnPaint)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        
        if 'wxMac' not in wx.PlatformInfo:
            self.Bind(wx.EVT_LEFT_UP, self.OnClick)
        else:
            self.Bind(wx.EVT_LEFT_DOWN, self.OnClick)        
        
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Show(True)
        
    def OnPaint(self, event):
        debug('Paint')
        canvas = wx.PaintDC(self)
        
        canvas.SetBrush(wx.WHITE_BRUSH)
        canvas.SetPen(wx.WHITE_PEN)
        canvas.DrawRectangle(0,0,465,132)
        
        canvas.DrawBitmap(self.boxBitmap,0,-60)
        canvas.SetBrush(wx.Brush(wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENU)))
        canvas.SetPen(wx.Pen(wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENU)))
        canvas.DrawRectangle(0,132,465,93)
        
        if 'wxMac' not in wx.PlatformInfo:
            canvas.SetFont(wx.Font(pointSize = 27, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL))
        else:
            canvas.SetFont(wx.Font(pointSize = 32, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL))
        canvas.DrawText("MailDrop", 290,30)
        
        if 'wxMac' not in wx.PlatformInfo:
            canvas.SetFont(wx.Font(pointSize = 8, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL))
        else:
            canvas.SetFont(wx.Font(pointSize = 10, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL))
        canvas.DrawText(VERSION, 420, 72)
        
        canvas.DrawBitmap(self.donateBitmap, self.donateClickBox.GetX(), self.donateClickBox.GetY(), True)
        
        canvas.DrawText(u'Copyright \xa9 2011 Michael Warren. All rights reserved.', 12, 172)
        
        if 'wxMac' not in wx.PlatformInfo:
            canvas.SetFont(wx.Font(pointSize = 8, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL, underline = True))
        else:
            canvas.SetFont(wx.Font(pointSize = 10, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL, underline = True))
        canvas.SetTextForeground(wx.BLUE)
        canvas.DrawText("Show Tutorial", self.tutorialClickBox.GetX(), self.tutorialClickBox.GetY())
        canvas.DrawText("www.getmaildrop.com", self.siteClickBox.GetX(), self.siteClickBox.GetY())
        
    def OnClick(self, event):
        debug('Click: ' + str(event.GetPosition()))
        if self.donateClickBox.Contains(event.GetPosition()):
            debug('Donate Button Clicked')
            #webbrowser.open("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4EXXPUPJPF9E4&lc=US&item_name=MailDrop&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted")
            webbrowser.open("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8LBAJM95VKCEE")
            
        if self.tutorialClickBox.Contains(event.GetPosition()):
            debug('Tutorial Link Clicked')
            TutorialGUI.TutorialGUI()
        if self.siteClickBox.Contains(event.GetPosition()):
            debug('Site Link Clicked')
            webbrowser.open("http://www.getmaildrop.com")
        event.Skip()
        
    def OnClose(self, event):
        self.Destroy()
        
if __name__ == '__main__':
    app = wx.App(False)   
    AboutGUI()  
    app.MainLoop()
        